﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Reflection;
using System.Text;
using T.FAS.Runtime.Term.Entity;
using T.ServiceComponent.DAC.Service;
using T.ServiceComponent.DataAccessEx.Core;

namespace T.FAS.Runtime.Term.Dao
{
    public class PageRefSchemaDao : DaoService<PageRefSchema>
    {
        public PageRefSchemaDao() :
           base()
        {
            DBName = "TFAS";
        }

        public override string TableName => "FAS_PageRefSchema";
        public override string IDColumnName => "PageMetaDataID";
        /// <summary>
        /// 获取Page引用明细
        /// </summary>
        /// <param name="pageId"></param>
        /// <returns></returns>
        public List<PageRefSchema> GetPageRefSchemas(string pageMetaDataID)
        {
            List<PageRefSchema> result = new List<PageRefSchema>();
            List<IDbDataParameter> paramList = new List<IDbDataParameter>();
            paramList.Add(DB.MakeInParam("@pageMetaDataID", TDbDataType.VarChar, pageMetaDataID));
            string sql = $"select * from {TableName} where PageMetaDataID=@pageMetaDataID";
            var ds = DB.ExecuteDataSet(sql, paramList.ToArray());
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    var row = ds.Tables[0].Rows[i];
                    result.Add(ConvertToObject(Columns, row));
                }
            }
            return result;
        }
    }
}
